home *** CD-ROM | disk | FTP | other *** search
/ DOpus Plus / DOpus Plus.iso / Tutorial / C Guide / Time_module / modinit.c < prev    next >
C/C++ Source or Header  |  1998-09-20  |  5KB  |  195 lines

  1. /****************************************************************************
  2.  
  3.  modinit.c - standard initialisation for Opus 5 modules
  4.  
  5.  ****************************************************************************/
  6.  
  7. #ifndef _DOPUS_MODULE_DEF
  8. #define _DOPUS_MODULE_DEF
  9. #include <dopus/modules.h>
  10. #endif
  11.  
  12. #ifndef CLIB_EXEC_PROTOS_H
  13. #include <clib/exec_protos.h>
  14. #include <pragmas/exec_pragmas.h>
  15. #endif
  16.  
  17. #ifndef EXEC_MEMORY_H
  18. #include <exec/memory.h>
  19. #endif
  20.  
  21. #ifndef CLIB_LOCALE_PROTOS_H
  22. #include <clib/locale_protos.h>
  23. #include <pragmas/locale_pragmas.h>
  24. #endif
  25.  
  26. /********************************************************************/
  27.  
  28. // SAS/C stuff
  29. int  __saveds __UserLibInit(void);
  30. void __saveds __UserLibCleanup(void);
  31.  
  32. struct Library *DOSBase;
  33. struct Library *AslBase;
  34. struct Library *GfxBase;
  35. struct Library *DOpusBase;
  36. struct Library *LocaleBase;
  37. struct Library *UtilityBase;
  38. struct Library *DiskfontBase;
  39. struct Library *GadToolsBase;
  40. struct Library *IntuitionBase;
  41.  
  42. #ifdef DATATYPES
  43. struct Library *DataTypesBase;
  44. #endif
  45. #ifdef AREXX
  46. struct Library *RexxSysBase; 
  47. #endif
  48.  
  49. APTR mempool;
  50.  
  51. // Locale pointer
  52. struct DOpusLocale *locale;
  53.  
  54.  
  55. // Library initialisation code
  56. __saveds __UserLibInit()
  57. {
  58.         // Initialise pointers
  59.         AslBase = 0;
  60.         GfxBase = 0;
  61.         DOpusBase=0;
  62.         LocaleBase=0;
  63.         UtilityBase=0;
  64.         DiskfontBase = 0;
  65.         GadToolsBase = 0;
  66.         IntuitionBase = 0;
  67.         
  68. #ifdef DATATYPES       
  69.         DataTypesBase = 0;
  70. #endif        
  71. #ifdef AREXX
  72.         RexxSysBase=0; 
  73. #endif
  74.                 
  75.         locale=0;
  76.         mempool = NULL;
  77.                        
  78.         // Get DOS library (can't really fail)
  79.         DOSBase=OpenLibrary("dos.library",0);
  80.  
  81.         // Open other libraries we need
  82.         if( !(AslBase = OpenLibrary("asl.library", 37)) ||
  83.             !(GfxBase=OpenLibrary("graphics.library",37)) ||
  84.             !(DOpusBase=OpenLibrary("dopus5.library",55)) ||
  85.             !(UtilityBase=OpenLibrary("utility.library",37)) ||
  86.             !(DiskfontBase=OpenLibrary("diskfont.library",37)) ||
  87.             !(GadToolsBase = OpenLibrary( "gadtools.library", 37)) ||
  88.             !(IntuitionBase = OpenLibrary( "intuition.library", 37)) ||
  89.             
  90. #ifdef DATATYPES           
  91.             !(DataTypesBase = OpenLibrary( "datatypes.library", 39)) ||
  92. #endif            
  93. #ifdef AREXX
  94.             !(RexxSysBase=OpenLibrary("rexxsyslib.library",0)) ||
  95. #endif      
  96.       
  97.             NULL 
  98.           )
  99.             return 1;
  100.         
  101.         if( !(mempool = NewMemHandle(4096, 3072, MEMF_CLEAR|MEMF_PUBLIC)) ||
  102.             !(locale = AllocMemH(mempool, sizeof(struct DOpusLocale))) )
  103.              {
  104.                 return 1;
  105.              } 
  106.         
  107.         
  108.         init_locale_data(locale);
  109.  
  110.         // Open locale library
  111.         if (LocaleBase=OpenLibrary("locale.library",38))
  112.         {
  113.                 // Store library pointer
  114.                 locale->li_LocaleBase=LocaleBase;
  115.  
  116.                 // Open catalog if name supplied
  117.                 if (module_info.locale_name)
  118.                 {
  119.                         struct TagItem tags[2];
  120.  
  121.                         // If MODULEF_CATALOG_VERSION is set, we do version checking
  122.                         tags[0].ti_Tag=(module_info.flags&MODULEF_CATALOG_VERSION)?OC_Version:TAG_IGNORE;
  123.                         tags[0].ti_Data=module_info.ver;
  124.                         tags[1].ti_Tag=TAG_END;
  125.  
  126.                         // Open catalog
  127.                         locale->li_Catalog=OpenCatalogA(NULL,module_info.locale_name,tags);
  128.                 }
  129.  
  130.                 // Get default lolale
  131.                 locale->li_Locale=OpenLocale(0);
  132.         }
  133.         
  134.       return NULL; // Succeeded
  135. }
  136.  
  137.  
  138. // Clean up
  139. void __saveds __UserLibCleanup()
  140. {
  141.         
  142.         if( mempool )
  143.           {
  144.              if( locale )
  145.                {
  146.                   if( LocaleBase )
  147.                     {
  148.                        CloseLocale(locale->li_Locale);
  149.                        CloseCatalog(locale->li_Catalog);
  150.                        CloseLibrary(LocaleBase);
  151.                     }
  152.                   FreeMemH(locale);
  153.                }
  154.              
  155.              FreeMemHandle( mempool );
  156.           }
  157.         
  158.         // Close libraries
  159.         CloseLibrary( AslBase );
  160.         CloseLibrary( GfxBase );
  161.         CloseLibrary( DOpusBase );
  162.         CloseLibrary( DiskfontBase );
  163.         CloseLibrary( UtilityBase );
  164.         
  165. #ifdef DATATYPES
  166.         CloseLibrary( DataTypesBase );
  167. #endif        
  168. #ifdef AREXX        
  169.         CloseLibrary( RexxSysBase );
  170. #endif        
  171.         
  172.         CloseLibrary( GadToolsBase );
  173.         CloseLibrary( IntuitionBase );
  174.         CloseLibrary( DOSBase );
  175. }
  176.  
  177.  
  178. // This routine is called by Opus to find out what the module does
  179. ModuleInfo *__asm __saveds L_Module_Identify(register __d0 int num)
  180. {
  181.         // Return module information
  182.         if (num==-1) return &module_info;
  183.  
  184.         // Valid function number?
  185.         if (num>module_info.function_count || !(module_info.function[num].desc)) return 0;
  186.  
  187.         // Return function description
  188.         return (ModuleInfo *)DOpusGetString(locale,module_info.function[num].desc);
  189. }
  190.  
  191. /********************************************************************/
  192.  
  193.  
  194.  
  195.